<template>
	<view>
		<u-navbar title="" @rightClick="rightClick" :border='false' :bgColor="bgColor" :autoBack="true">
		</u-navbar>
		<view class=" content">
			<view class="content_top u-font-40 u-font-bold flex-cneter">
				渠道邀请码
			</view>
			<view class="erweima">
				<image :src="images" mode=""></image>
			</view>
			<view class="flex-cneter">
				二维码邀请用户，下单后可得分成
			</view>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="submit-btn" @click="download">
			二维码保存至本地
		</view>
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<view class="submit-btn" @click="copya(images)">
			长按二维码保存至本地
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	import configs from '@/common/config.js'
	export default {
		data() {
			return {
				bgColor: ' #ECF9F8',
				info: {},
				images: ''
			};
		},
		onLoad() {
			this.init()
		},
		methods: {
			copya(url) {
				uni.previewImage({
					urls: [url]
				})
			},
			init() {
				this.$api.post('/channelinfo', {}).then(res => {
					
					this.info = res.data;
					this.images = configs.url + res.data.share_url
				})
			},
			download(url) {
				uni.downloadFile({
					url: this.images, //仅为示例，并非真实的资源
					success: (res) => {
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.$u.toast(`保存成功`)
									
								}
							});
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ECF9F8;
		box-sizing: border-box;
	}

	.content {
		width: 80vw;
		margin: 20vh auto;
		border-radius: 30rpx;
		height: 878rpx;
		background-color: #fff;
		box-shadow: 0rpx 0rpx 30rpx #999;
		;

		.content_top {
			background-color: $uni-primary;
			color: #fff;
			border-radius: 30rpx 30rpx 0 0;
			height: 150rpx;
		}

		.erweima {
			border: 1rpx solid #111;
			width: 375rpx;
			height: 375rpx;
			margin: 100rpx auto;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>